const mixin = {//通用部分
    computed: {
        Type() {
            return function (row) {
                if (parseInt(row.Refunded_Quantity) == parseInt(row.Quantity)) {
                    return ["已退款", "danger", false];
                } else {
                    let str = row.Row_Status
                    switch (str) {
                        case "0":
                            return ["待发货", "", true];
                        case "1":
                            return ["发货中", "warning", true];
                        case "2":
                            return ["已发货", "success", true];
                        case "3":
                            return ["已收货","success",true];
                        default:
                            return ""
                    }
                }
            }
        }
    }
}
Vue.component('yl-button', {
    template: `
    <span>
        <el-button :type="type" @click="Export" :loading="loading">
            <slot></slot>
        </el-button>
        <el-table id="ExportData" :data="data" style="display: none; width: 100%;margin-bottom: 20px;">
            <el-table-column align="center" prop="Sales_Order_Detail_SerialNumber"  label="订单明细编号"></el-table-column>
            <el-table-column align="center" prop="Sales_Order_SerialNumber" label="订单编号"></el-table-column>
            <el-table-column align="center" prop="Supplier_Name" label="供应商"></el-table-column>
            <el-table-column align="center" prop="Article_Name" label="商品名称"></el-table-column>
            <el-table-column align="center" prop="Specifications_Name" label="规格名称"></el-table-column>
            <el-table-column align="center" prop="Supplier_Article_SerialNumber" label="供应商品编号"></el-table-column>
            <el-table-column align="center" prop="Sales_Date" label="下单时间"></el-table-column>
            <el-table-column align="center" prop="Quantity" label="共发货总量"></el-table-column>
            <el-table-column align="center" prop="Delivery_Quantity" label="已发货数量"></el-table-column>
            <el-table-column align="center" label="剩余发货数量">
                <template v-slot="{row}">
                    {{parseInt(row.Quantity)-parseInt(row.Delivery_Quantity)}}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="Row_Status" label="发货状态">
                <template v-slot="{row}">
                    <el-tag>{{Type(row)[0]}}</el-tag>
                </template>
            </el-table-column>
        </el-table>
    </span>`,
    props: ['loading', 'data', 'type'],
    mixins: [mixin],
    methods: {
        Export() {
            this.$emit('click')
        }
    }
})
Vue.component('show-logistics', {//修改记录组件
    template: `<el-dialog title="物流信息" :visible.sync="visibleDialog" width="80vw">
        <el-table v-if="dialogVisible" :data="tableData" stripe border max-height="50vh" style="width: 100%">
            <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
            <el-table-column align="center" prop="Article_Name" label="商品名称"></el-table-column>
            <el-table-column align="center" prop="Specifications_Name" label="规格名称"></el-table-column>
            <el-table-column align="center" prop="Logistics_Name" label="物流公司"></el-table-column>
            <el-table-column align="center" prop="Logistics_Number" label="物流编号">
                <template v-slot="{row}">
                    <span style="cursor: pointer;" @click="showLogistics(row.Logistics_Number)">{{ row.Logistics_Number ? row.Logistics_Number : '暂无物流单号'}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" prop="Delivery_Quantity" label="当前发货数量"></el-table-column>
            <el-table-column align="center" prop="Quantity" label="需发货总数量"></el-table-column>
        </el-table>
        <el-form v-else ref="contract" :model="form" :rules="rules" :inline-message="true">
            <el-descriptions :column="1" border size="small">
                <el-descriptions-item label="商品名称">
                    <el-form-item prop="Article_Name">
                        <el-input disabled v-model.trim="data.Article_Name"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="物流公司">
                    <el-form-item prop="Logistics_Code">
                        <el-select v-model.trim="form.Logistics_Code" filterable clearable style="width: 100%;" placeholder="请选择物流公司">
                            <el-option v-for="item in logistics" :key="item.Logistics_Code" :label="item.Logistics_Name" :value="item.Logistics_Code"></el-option>
                        </el-select>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="物流编号">
                    <el-form-item prop="Logistics_Number">
                        <el-input v-model.trim="form.Logistics_Number" placeholder="请输入物流编号"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="发货数量">
                    <el-form-item prop="Delivery_Quantity">
                        <el-input-number v-model="form.Delivery_Quantity" :min="1" :max="max"></el-input-number>
                        <span style="font-size: 12px;font-weight: 700;">需发货：{{data.Quantity}}&nbsp;&nbsp;&nbsp;已发货：{{data.Delivery_Quantity}}</span>
                    </el-form-item>
                </el-descriptions-item>
            </el-descriptions>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="$emit('update:visible',false)">取消</el-button>
            <el-button v-if="!dialogVisible" @click="dialogVisible=true">返回</el-button>
            <el-button :disabled="max==0||!Type(data)[2]" :loading="loading" :type="max!=0&&Type(data)[2]?'primary':'info'" @click="submitForm('contract')">{{dialogVisible?'添加发货信息':'提交'}}</el-button>
        </span>
    </el-dialog>`,
    props: ['data', 'visible'],
    data() {
        return {
            visibleDialog: false,
            dialogVisible: true,
            tableData: [],//详情
            logistics: [],
            form: {
                Sales_Order_Logistics_SerialNumber: '',
                Sales_Order_Detail_SerialNumber: '',
                Logistics_Number: '',
                Logistics_Code: '',
                Delivery_Quantity: 1,
                Delivery_Data: '',
                Row_Status:'',
            },
            rules: {
                Logistics_Code: [{ required: true, message: '请选择物流公司', trigger: 'change' }],
                Logistics_Number: [{ required: true, message: '请输入物流编号', trigger: 'blur' }]
            },
            loading: false,
        }
    },
    mixins: [mixin],
    computed: {
        max() {
            let max = parseInt(this.data.Refundable_Quantity) - parseInt(this.data.Delivery_Quantity)
            return max >= 0 ? max : 0;
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            this.dialogVisible = true;
        },
        'data.Sales_Order_Detail_SerialNumber': function (val) {
            this.tableData = [];
            this.getList(val);
        }
    },
    mounted() {
        this.getData();
    },
    methods: {
        showLogistics(Data) {
            const that = this;
            const h = this.$createElement;
            $.ajax({
                url: `${BASE_URL1}/getWayBillStatus?grant_type=tourist`,
                type: 'GET',
                data: { Data },
                success: function (res) {
                    that.$msgbox({
                        title: '查看物流信息',
                        message: h('div', { style: { marginLeft: '-40px' } }, [
                            h('logistics', {
                                props: {
                                    data: res.message == 'ok' ? res.data : []
                                }
                            })
                        ]),
                        customClass: 'logistics-message-box',
                        showCancelButton: false,
                        confirmButtonText: '确定',
                    }).then(action => { });
                },
                dataType: "json"
            });
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                type: 'GET',
                data: {
                    Data: 'business_logistics_info',
                    Condition: "Row_Status='0'",
                },
                success: function (Result) {
                    that.logistics = Result;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList(Sales_Order_Detail_SerialNumber) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data: {
                    SQLSerialNumber: 'A_business_logistics_info',
                    Condition: window.btoa(unescape(encodeURIComponent(Sales_Order_Detail_SerialNumber))),
                    ExtensionCondition: ''
                },
                success: function (Result) {
                    that.tableData = Result;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        submitForm(formName) {//提交
            if (this.dialogVisible) {//提交发货信息
                this.dialogVisible = false;
            } else {
                const that = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        that.loading = true;
                        //获取要修改的表
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/member/getMemberPoint`,
                            type: 'POST',
                            data: {
                                Data: JSON.stringify([{
                                    tableName: 'business_sales_order',
                                    Condition: window.btoa(unescape(encodeURIComponent("Sales_Order_SerialNumber='" + that.data.Sales_Order_SerialNumber + "'"))),
                                }, {
                                    tableName: 'business_sales_order_detail',
                                    Condition: window.btoa(unescape(encodeURIComponent("Sales_Order_Detail_SerialNumber='" + that.data.Sales_Order_Detail_SerialNumber + "'"))),
                                }]),
                            },
                            success: function ({ business_sales_order, business_sales_order_detail }) {
                                if (business_sales_order.length == 1 && business_sales_order_detail.length == 1) {
                                    that.form.Delivery_Data = getYMDHMSDate();
                                    that.form.Sales_Order_Detail_SerialNumber = that.data.Sales_Order_Detail_SerialNumber;
                                    //修改销售订单状态
                                    let Status = business_sales_order[0].Row_Status.charAt(0);
                                    if (parseInt(that.data.Quantity) == parseInt(that.data.Delivery_Quantity) + parseInt(that.form.Delivery_Quantity)) {
                                        business_sales_order[0].Row_Status = Status + '4'//发货中
                                        business_sales_order_detail[0].Row_Status = '2'//明细发货但没完成
                                    } else {
                                        business_sales_order_detail[0].Row_Status = '1'//明细发货完成
                                    }
                                    $.ajax({
                                        headers: requestHeaders(),
                                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                                        type: 'POST',
                                        data: {
                                            Data: JSON.stringify({
                                                Add: { business_sales_order_logistics: [that.form], base_operation_log: [generateLog('发货', '平台端操作', 'business_sales_order', JSON.stringify({ Modify: { business_sales_order, business_sales_order_detail }, Add: { business_sales_order_logistics: [that.form] } }))] },
                                                Modify: { business_sales_order, business_sales_order_detail }
                                            })
                                        },
                                        success: function (res) {
                                            if (res.Status === 'success') {
                                                //订阅快递100
                                                $.ajax({
                                                    headers: requestHeaders(),
                                                    url: `${BASE_URL2}/waybill/subscribeWayBillState?Data=${that.form.Logistics_Number}`,
                                                    type: 'GET',
                                                    success: function (res) {
                                                        that.$message.success("提交成功");
                                                        that.form = {
                                                            Sales_Order_Logistics_SerialNumber: '',
                                                            Sales_Order_Detail_SerialNumber: '',
                                                            Logistics_Number: '',
                                                            Logistics_Code: '',
                                                            Delivery_Quantity: 1,
                                                            Delivery_Data: '',
                                                        }
                                                        that.getList(that.data.Sales_Order_Detail_SerialNumber);
                                                        that.$emit('success')
                                                        that.$emit('update:visible', false)
                                                    },
                                                    complete: function (XMLHttpRequest) {
                                                        that.loading = false
                                                        requestPretreatment(XMLHttpRequest);
                                                    },
                                                    dataType: "json"
                                                })
                                            } else {
                                                that.$message.error("提交失败，请稍后再试")
                                            }
                                        },
                                        complete: function (XMLHttpRequest) {
                                            that.loading = false
                                            requestPretreatment(XMLHttpRequest);
                                        },
                                        dataType: "json"
                                    })
                                } else {
                                    that.loading = false
                                }
                            },
                            complete: function (XMLHttpRequest) {
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    } else {
                        that.$message({
                            message: sumberError,
                            type: 'warning'
                        })
                        return false;
                    }
                });
            }
        }
    }
})
Vue.component('field-config', {
    template: `<el-dialog title="字段配置" :visible.sync="visibleDialog" width="80vw">
    <el-checkbox-group id="field_config" v-model="checkList">
        <el-checkbox :label="item.value" border v-for="(item,index) in field" :key="index">{{item.label}}</el-checkbox>
    </el-checkbox-group>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">取消</el-button>
        <el-button type="primary" @click="submitForm()">保存</el-button>
    </span></el-dialog>`,
    props: ['value', 'visible'],
    data() {
        return {
            data: this.value,
            visibleDialog: false,
            checkList: [],
            field: [{
                label: '序号',
                value: 'index',
            }, {
                label: '操作',
                value: 'config',
            }, {
                label: '订单明细编号',
                value: 'Sales_Order_Detail_SerialNumber',
            }, {
                label: '订单编号',
                value: 'Sales_Order_SerialNumber',
            }, {
                label: '供应商品编号',
                value: 'Supplier_Article_SerialNumber',
            }, {
                label: '供应商',
                value: 'Supplier_Name',
            }, {
                label: '商品名称',
                value: 'Article_Name',
            }, {
                label: '规格名称',
                value: 'Specifications_Name',
            }, {
                label: '所属活动',
                value: 'Activity_Name',
            }, {
                label: '下单人',
                value: 'Member_Name',
            }, {
                label: '下单人手机号',
                value: 'Member_SerialNumber',
            }, {
                label: '收货人',
                value: 'Sales_Contacts',
            }, {
                label: '收货人手机号',
                value: 'Sales_Phone',
            }, {
                label: '收货地址',
                value: 'Sales_Address',
            }, {
                label: '下单数量',
                value: 'Quantity',
            }, {
                label: '退款数量',
                value: 'Refunded_Quantity',
            }, {
                label: '销售单价',
                value: 'Sales_Unit_Price',
            }, {
                label: '销售总价',
                value: 'Sales_Amount',
            }, {
                label: '实收金额',
                value: 'Reality_Amount',
            }, {
                label: '积分消费',
                value: 'Sales_Point',
            }, {
                label: '采购单价',
                value: 'Purchase_Unit_Price',
            }, {
                label: '采购总价',
                value: 'Purchase_Amount',
            }, {
                label: '下单时间',
                value: 'Sales_Date',
            }, {
                label: '收款时间',
                value: 'Collection_Date',
            }, {
                label: '已发货数量',
                value: 'Delivery_Quantity',
            }, {
                label: '未发货数量',
                value: 'UNDelivery_Quantity',
            }, {
                label: '物流公司',
                value: 'Logistics_Name',
            }, {
                label: '物流单号',
                value: 'Logistics_Number',
            }, {
                label: '发货状态',
                value: 'Row_Status',
            }],
        }
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            this.dialogVisible = true;
        },
        value(val) {
            this.data = val;
        },
        data(val) {
            let List = [];
            this.field.forEach(item => {
                if (!val.some(i => i == item.value)) {
                    List.push(item.value)
                }
            })
            this.checkList = List
            this.$emit('input', val);
        }
    },
    methods: {
        submitForm() {
            let fieldList = [];
            this.field.forEach(item => {
                if (!this.checkList.some(i => i == item.value)) {
                    fieldList.push(item.value);
                }
            })
            setField('deliver_order', fieldList, (Result) => {
                if (Result.Status == "success") {
                    this.$emit('success')
                    this.$emit('update:visible', false)
                }
            })
        }
    }
})
new Vue({
    el: '#app',
    data() {
        return {
            field: [],//字段展示
            table: false,
            form: {
                SQLSerialNumber: "P_business_sales_order_detail1",
                PaginationNumber: 1,//页数
                RowAmount: 20,//每页数据条数
                Condition: '',
                ExtensionCondition: '',
                Supplier_SerialNumber: '',
                Member_SerialNumber:'',
                Sales_Contacts:'',
                Sales_Order_SerialNumber: '',
                Sales_Date: null,
                Article_Name:'',
                Sales_Phone:'',
                Member_Name:'',
                Row_Status:'',
            },
            Supplier: [],
            total: 0,
            tableData: [],	//表格数据
            ExportData: [],//导出
            loading: false,
            dialogVisible: false,//物流
            dialogVisible1: false,//明细
            dialogVisible2: false,
            Sales_Order: {},//当前选中的订单
            Sales_Order1: {},//明细
        }
    },
    mounted() {
        getField('deliver_order', (field) => { this.field = field, this.table = true });
        this.getData();
        this.getList(this.form);//前端分页
    },
    mixins: [mixin],
    computed: {
        Color() {
            return function (row) {
                if ((parseInt(row.Quantity) - parseInt(row.Delivery_Quantity)) == 0) {
                    return "#67C23A"
                } else if (parseInt(row.Delivery_Quantity) == 0) {
                    return "#F56C6C"
                } else if ((parseInt(row.Quantity) - parseInt(row.Delivery_Quantity)) > 0) {
                    return "#E6A23C"
                }
            }
        },
        Show() {
            return {
                index: !this.field.some(i => i == "index"),
                config: !this.field.some(i => i == "config"),
                Sales_Order_Detail_SerialNumber: !this.field.some(i => i == "Sales_Order_Detail_SerialNumber"),
                Sales_Order_SerialNumber: !this.field.some(i => i == "Sales_Order_SerialNumber"),
                Supplier_Name: !this.field.some(i => i == "Supplier_Name"),
                Article_Name: !this.field.some(i => i == "Article_Name"),
                Specifications_Name: !this.field.some(i => i == "Specifications_Name"),
                Supplier_Article_SerialNumber: !this.field.some(i => i == "Supplier_Article_SerialNumber"),
                Purchase_Unit_Price: !this.field.some(i => i == "Purchase_Unit_Price"),
                Sales_Date: !this.field.some(i => i == "Sales_Date"),
                Collection_Date: !this.field.some(i => i == "Collection_Date"),
                Quantity: !this.field.some(i => i == "Quantity"),
                Refunded_Quantity: !this.field.some(i => i == "Refunded_Quantity"),
                Delivery_Quantity: !this.field.some(i => i == "Delivery_Quantity"),
                UNDelivery_Quantity: !this.field.some(i => i == "UNDelivery_Quantity"),
                Row_Status: !this.field.some(i => i == "Row_Status"),
                Member_Name: !this.field.some(i => i == "Member_Name"),
                Sales_Contacts: !this.field.some(i => i == "Sales_Contacts"),
                Sales_Address: !this.field.some(i => i == "Sales_Address"),
                Sales_Amount: !this.field.some(i => i == "Sales_Amount"),
                Reality_Amount: !this.field.some(i => i == "Reality_Amount"),
                Sales_Point: !this.field.some(i => i == "Sales_Point"),
                Logistics_Number: !this.field.some(i => i == "Logistics_Number"),
                Activity_Name: !this.field.some(i => i == "Activity_Name"),
                Logistics_Name: !this.field.some(i => i == "Logistics_Name"),
                Purchase_Amount: !this.field.some(i => i == "Purchase_Amount"),
                Sales_Unit_Price: !this.field.some(i => i == "Sales_Unit_Price"),
                Sales_Phone: !this.field.some(i => i == "Sales_Phone"),
                Member_SerialNumber: !this.field.some(i => i == "Member_SerialNumber"),
            }
        }
    },
    watch: {
        field() {
            const timer = setTimeout(() => {
                this.table = true;
                clearTimeout(timer)
            })
        }
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                type: 'GET',
                data: {
                    Data: 'business_supplier_info',
                    Condition: "Row_Status <> '1'",
                },
                success: function (res) {
                    that.Supplier = res;
                },
                error: function () {
                    that.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            data.Condition = window.btoa(unescape(encodeURIComponent("%" + data.Sales_Order_SerialNumber + "%,%" + data.Sales_Order_SerialNumber + "%")))
            let sql = "";
            if (data.Sales_Date) {
                sql = sql + "AND business_sales_order.Sales_Date BETWEEN '" + data.Sales_Date[0] + "' AND '" + data.Sales_Date[1] + "'\r\n"
            }
            if (data.Supplier_SerialNumber) {
                sql = sql + "AND business_sales_order_detail.Supplier_SerialNumber = '" + data.Supplier_SerialNumber + "'\r\n"
            }
            if(data.Article_Name){
                sql = sql + "AND business_sales_order_detail.Article_Name LIKE '%"+data.Article_Name+"%'\r\n"
            }
            if(data.Sales_Phone){
                sql = sql + "AND business_sales_order.Sales_Phone LIKE '%"+data.Sales_Phone+"%'\r\n"
            }
            if(data.Member_SerialNumber){
                sql = sql + "AND business_member_info.Member_SerialNumber LIKE '%"+data.Member_SerialNumber+"%'\r\n"
            }
            if(data.Member_Name){
                sql = sql + "AND business_member_info.Member_Name LIKE '%"+data.Member_Name+"%'\r\n"
            }
            if(data.Sales_Contacts){
                sql = sql + "AND business_sales_order.Sales_Contacts LIKE '%"+data.Sales_Contacts+"%'\r\n"
            }
            if (data.Row_Status == '1') {
                sql = sql + "AND business_sales_order_detail.Row_Status = '0'";
            } else if (data.Row_Status == '2') {
                sql = sql + "AND business_sales_order_detail.Row_Status = '1'";
            } else if (data.Row_Status == '3') {
                sql = sql + "AND business_sales_order_detail.Row_Status = '2'";
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));

            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                    that.table = false;
                    const timer = setTimeout(() => {
                        that.table = true;
                        clearTimeout(timer)
                    })
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        showLogistics(Data) {
            const that = this;
            const h = this.$createElement;
            $.ajax({
                url: `${BASE_URL1}/getWayBillStatus?grant_type=tourist`,
                type: 'GET',
                data: { Data },
                success: function (res) {
                    that.$msgbox({
                        title: '查看物流信息',
                        message: h('div', { style: { marginLeft: '-40px' } }, [
                            h('logistics', {
                                props: {
                                    data: res.message == 'ok' ? res.data : []
                                }
                            })
                        ]),
                        customClass: 'logistics-message-box',
                        showCancelButton: false,
                        confirmButtonText: '确定',
                    }).then(action => { });
                },
                dataType: "json"
            });
        },
        handleLogistics(command, row) {//物流信息
            const that = this;
            if (command == "Logistics") {
                this.Sales_Order = row;
                this.dialogVisible = true;
            } else if (command == "Detail") {
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                    type: 'POST',
                    data: {
                        SQLSerialNumber: 'P_business_sales_order',
                        Condition: window.btoa(unescape(encodeURIComponent("%" + row.Sales_Order_SerialNumber + "%"))),
                        ExtensionCondition: '',
                    },
                    success: function (Result) {
                        if (Result.length == 1) {
                            that.Sales_Order1 = Result[0];
                            that.dialogVisible1 = true;
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                });
            }
        },
        downloadTemplate(command) {
            if (command == "logistics") {
                window.location.href = './download/发货物流信息模板.xlsx';
            } else if (command == "logisticsData") {
                this.$message({
                    message: '正在下载全国物流公司数据信息，请勿频繁点击！',
                    type: 'success'
                })
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                    type: 'POST',
                    data: {
                        Data: 'business_logistics_info',
                        Condition: '',
                    },
                    success: function (res) {
                        const wb = XLSX.utils.book_new();
                        const ws_data = [['公司名称', '公司编号']]
                        res.forEach(item => {
                            ws_data.push([item.Logistics_Name, item.Logistics_Code])
                        })
                        const ws = XLSX.utils.aoa_to_sheet(ws_data);
                        ws['!cols'] = [];
                        ws_data[0].forEach(item => {
                            ws['!cols'].push({ alignment: { horizontal: "center" }, wpx: 200 });
                        })
                        XLSX.utils.book_append_sheet(wb, ws, "全国物流公司信息明细表");
                        XLSX.writeFile(wb, "全国物流公司信息明细表" + (+new Date()) + ".xlsx");
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }
        },
        importTemplate(command) {
            if (command == "logistics") {
                window.location.href = './import.html';
            }
        },
        Export(form) {//导出
            const that = this;
            this.loading = true;
            let data = deepClone(form);
            data.Condition = window.btoa(unescape(encodeURIComponent("%" + data.Sales_Order_SerialNumber + "%,%" + data.Sales_Order_SerialNumber + "%")))
            let sql = "";
            if (data.Sales_Date) {
                sql = sql + "AND business_sales_order.Sales_Date BETWEEN '" + data.Sales_Date[0] + "' AND '" + data.Sales_Date[1] + "'\r\n"
            }
            if (data.Supplier_SerialNumber) {
                sql = sql + "AND business_sales_order_detail.Supplier_SerialNumber = '" + data.Supplier_SerialNumber + "'\r\n"
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    if (Result.length > 0) {
                        let ExportData = [];
                        Result.forEach(item => {
                            let obj = ExportData.filter(i => i.Supplier_SerialNumber == item.Supplier_SerialNumber)[0];
                            if (obj) {
                                obj.Data.push(item);
                            } else {
                                ExportData.push({
                                    Supplier_SerialNumber: item.Supplier_SerialNumber,
                                    Supplier_Name: item.Supplier_Name,
                                    Data: [item]
                                })
                            }
                        })
                        console.log(ExportData);
                        const wb = XLSX.utils.book_new();
                        ExportData.forEach(item => {
                            const ws_data = [
                                ["订单明细编号", "订单编号", "供应商", "商品名称", "规格名称", "供应商品编号", "下单时间", "共发货总量", "已发货数量", "剩余发货数量", "发货状态"]
                            ];
                            item.Data.forEach(i => {
                                ws_data.push([
                                    i.Sales_Order_Detail_SerialNumber,
                                    i.Sales_Order_SerialNumber,
                                    i.Supplier_Name,
                                    i.Article_Name,
                                    i.Specifications_Name,
                                    i.Supplier_Article_SerialNumber,
                                    i.Sales_Date,
                                    i.Quantity,
                                    i.Delivery_Quantity,
                                    parseInt(i.Quantity) - parseInt(i.Delivery_Quantity),
                                    that.Type(i)[0]
                                ])
                            })
                            const ws = XLSX.utils.aoa_to_sheet(ws_data);
                            ws['!cols'] = [];
                            ws_data[0].forEach(item => {
                                ws['!cols'].push({ alignment: { horizontal: "center" }, wpx: 150 });
                            })
                            XLSX.utils.book_append_sheet(wb, ws, item.Supplier_Name);
                        })
                        XLSX.writeFile(wb, "发货物流信息表" + (+new Date()) + ".xlsx");
                        that.$message({
                            message: '已成功导出',
                            type: 'success'
                        })
                        // that.ExportData = Result;
                        // that.$nextTick(() => {
                        //     let wb = XLSX.utils.table_to_book(document.querySelector("#ExportData"));
                        //     var wbout = XLSX.write(wb, {
                        //         bookType: "xlsx",
                        //         bookSST: true,
                        //         type: "array"
                        //     });

                        //     try {
                        //         saveAs(
                        //             new Blob([wbout], {
                        //                 type: "application/octet-stream"
                        //             }),
                        //             "发货物流信息表" + (+new Date()) + ".xlsx"
                        //         );
                        //     } catch (e) {
                        //         if (typeof console !== "undefined") console.log(e, wbout);
                        //     }
                        //     that.$message({
                        //         message: '已成功导出',
                        //         type: 'success'
                        //     })
                        //     return wbout;
                        // })
                    } else {
                        that.$message({
                            message: '暂无可导出的数据',
                            type: 'warning'
                        })
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        }
    },
})